﻿/*======================================*\
* Author: Vincent
* LastModifyUser: Vincent
* Description:  
* CreateTime： 2012-05
* Remark:  
\*======================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppCode.DbDTO;
using AppCode.Contract;

namespace AppCode.Domain.Repositories
{
    /// <summary>
    /// 数据库信息
    /// <remarks>
    /// 包含表信息，库信息，从配置加载
    /// </remarks>
    /// </summary>
    [Serializable]
    public class DbInfo:IAggregateRoot
    {
        /// <summary>
        /// 数据库连接信息
        /// </summary>
        public DbConnInfo DbConnStrInfo { get; set; }

        /// <summary>
        /// 对应的表信息
        /// <remarks>
        /// 按需加载
        /// </remarks>
        /// </summary>
        public IList<TableInfo> DbTableInfo { get; set; }

        /// <summary>
        /// 所有表信息
        /// </summary>
        public IList<string> DbTables { get; set; }

        /// <summary>
        /// 当前需要处理的表
        /// </summary>
        public IList<string> DbTablesNeedHandler { get; set; }

        /// <summary>
        /// 从原集合中取得表字段信息
        /// </summary>
        public TableInfo GetTableInfo(string tableName)
        {
            if (DbTableInfo != null && DbTableInfo.Count > 0)
            {
                return DbTableInfo.Where(a => a.TableName == tableName).ElementAt(0);
            }
            return null;
        }
    }
}
